﻿package domino 
{

	/**
	 * ...
	 * @author ...
	 */
		import flash.display.MovieClip;
	import flash.display.DisplayObjectContainer;
	import flash.geom.Point;
	import flash.display.Sprite;
	
	import Box2D.Dynamics.*;
	import Box2D.Collision.*;
	import Box2D.Collision.Shapes.*;
	
	
	public class actorCircle extends actor
	{
		private static const BALL_D:int = 32;
		public var stat:Number;
		public var circle:Sprite = new ball();
		public var scaleX, scaleY;
		public var density, angV;
		public var isSensor:int;
		public function actorCircle(_world:b2World,parent:DisplayObjectContainer,dominPosition:Point,_rot:Number,_density:Number,_friction:Number,_scaleX:Number,_scaleY:Number,_restitution:Number,_isSensor:int) 
		{ 
			//costume
			//var radius:int=3;
			//circle = new ball();
			circle.scaleX = _scaleX;
			circle.scaleY = _scaleX;
			scaleX = _scaleX;
			scaleY = _scaleX;
			circle.x = dominPosition.x;
			circle.y = dominPosition.y;
			//circle.rotation = _rot;
			parent.addChild(circle);
			//body
			isSensor = _isSensor;
			var final_body:b2Body;
			var the_circle:b2CircleDef = new b2CircleDef() ;
			
			the_circle.radius = circle.width / 60; ;
			the_circle.friction=_friction;
			the_circle.density = _density;
			the_circle.restitution = _restitution;
			the_circle.isSensor = isSensor;
			
			density = _density;
			angV = 0;
			
			var the_body:b2BodyDef = new b2BodyDef();
			the_body.position.Set(circle.x/30,circle.y/30);
			the_body.angle = _rot * Math.PI / 180;
			final_body=_world.CreateBody(the_body);
			final_body.AllowSleeping(true);
			final_body.CreateShape(the_circle);
			
			final_body.SetMassFromShapes();
			trace("mass is" + final_body.GetMass());
		   //  final_body.SetMass(new b2MassData())     
//			 final_body.getM
			super(final_body,circle);
			setMovie(_density) ;
        }
	
	 public function getData():Array {
		var data:Array = new Array();
		data.push(Number(_costume.x));
		data.push(Number(_costume.y));
		data.push(Number(circle.scaleX));
		data.push(Number(circle.scaleY));
		data.push(Number(_body.GetShapeList().GetFriction()));
		data.push(Number(_body.GetShapeList().m_density));
		data.push(Number(_costume.rotation));
		data.push(_body.GetShapeList().GetRestitution());
		data.push(0);
		return data;
	}
		
          function setMovie(s:Number) {
			if(s==0)
			 MovieClip(_costume).gotoAndStop(2);
			else
			 MovieClip(_costume).gotoAndStop(1);
			 
			}
	}
     
}